class IsometricGamePlayerController extends PlayerController;
var bool bPawnNearDestination;
var float DistanceRemaining; 
var bool shift, bThirdPerson;

enum EMouseEvent
{
  LeftMouseButton,
  RightMouseButton,
  MiddleMouseButton,
  ScrollWheelUp,
  ScrollWheelDown,
};

state PlayerFlying
{


}
event ResetCameraMode()
{
	if ( Pawn != None )
	{	// If we have a pawn, let's ask it which camera mode we should use
		SetCameraMode( Pawn.GetDefaultCameraMode( Self ) );
	}
	else
	{	// otherwise default to first person view.
		SetCameraMode( 'FirstPerson' );
		`Log("nopawn");
	}
}
 exec function NextWeapon()
    {
    PlayerCamera.FreeCamDistance += 64;
    }

    exec function PrevWeapon()
    {
    PlayerCamera.FreeCamDistance -= 64;
    }



// Handle mouse inputs
function HandleMouseInput(EMouseEvent MouseEvent, EInputEvent InputEvent)
{
  local FinalHUD yarg;
  local MyPlayerInput mine;

  // Type cast to get our HUD
  yarg = FinalHUD(myHUD);
  mine = MyPlayerInput(PlayerInput);
  if (yarg != None)
  {
    // Detect what kind of input this is
    if (InputEvent == IE_Pressed)
    {
      // Handle pressed event
      switch (MouseEvent)
      {
        case LeftMouseButton:
		yarg.startPos.X = mine.MousePosition.X;
		yarg.startPos.Y = mine.MousePosition.Y;
	  yarg.PendingLeftPressed = true;
	  break;

	case RightMouseButton:
	  yarg.PendingRightPressed = true;
	  break;

	case MiddleMouseButton:
	  yarg.PendingMiddlePressed = true;
	  break;

	default:
	  break;
      }
    }
    else if (InputEvent == IE_Released)
    {
      // Handle released event
      switch (MouseEvent)
      {
        case LeftMouseButton:
	  yarg.PendingLeftReleased = true;
	  	  yarg.PendingLeftPressed = false;
	  break;

	case RightMouseButton:
	  yarg.PendingRightReleased = true;
	  break;

	case MiddleMouseButton:
	  yarg.PendingMiddleReleased = true;
	  break;

	default:
	  break;
      }
    }
  }
}

// Hook used for the left and right mouse button when pressed
exec function StartFire(optional byte FireModeNum)
{
  HandleMouseInput((FireModeNum == 0) ? LeftMouseButton : RightMouseButton, IE_Pressed);
  Super.StartFire(FireModeNum);
}

// Hook used for the left and right mouse button when released
exec function StopFire(optional byte FireModeNum)
{
  HandleMouseInput((FireModeNum == 0) ? LeftMouseButton : RightMouseButton, IE_Released);
  Super.StopFire(FireModeNum);
}

// Called when the middle mouse button is pressed
exec function MiddleMousePressed()
{
  HandleMouseInput(MiddleMouseButton, IE_Pressed);
}

// Called when the middle mouse button is released
exec function MiddleMouseReleased()
{
  HandleMouseInput(MiddleMouseButton, IE_Released);
}

// Called when the middle mouse wheel is scrolled up
exec function MiddleMouseScrollUp()
{
  HandleMouseInput(ScrollWheelUp, IE_Pressed);
}

// Called when the middle mouse wheel is scrolled down
exec function MiddleMouseScrollDown()
{
  HandleMouseInput(ScrollWheelDown, IE_Pressed);
}
simulated event PostBeginPlay(){
	super.PostBeginPlay();
/*if(type==0){
               SpawnHumanPawn(Vect(0,0,0));
               }
if(type==1){
               SpawnZombiePawn(Vect(0,0,0));
               }*/
			   
}
function SpawnHumanPawn(Vector spawnspot){
			local Pawn ResultPawn;
           Possess(spawn(class'myPawn', , ,  spawnspot, , ,), false);
           Tag='human';
           `Log("Human Spawned");
}

function vector SpawnPoint(int type){
  local vector SpawnPoint;
  SpawnPoint=vect(0,0,0);
//arrays of potential spawn points for humans and zombies
//random integer generator to pick a spawn point and check it's not occupied
//assign SpawnPoint
return SpawnPoint;
}
function SpawnZombiePawn(Vector spawnspot){
local Pawn ResultPawn;
           Possess(spawn(class'myPawn', , ,  spawnspot, , ,), false);
           Tag='zombie';
           `Log("Zombie Spawned");
           if(ResultPawn != none)
	{
		//PlayerSpawned(spawnspot);
	}
}
// Null this function

// Override this state because StartFire isn't called globally when in this function
state PlayerWalking 
{
	function PlayerMove(float DeltaTime)
	{
		local vector X,Y,Z;
	
		GetAxes(Rotation,X,Y,Z);
		Pawn.Acceleration = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
		Pawn.Acceleration = Pawn.AccelRate * Normal(Pawn.Acceleration);
		if(PlayerInput.aForward == 0 || PlayerInput.aStrafe == 0)
			{
			pawn.velocity.X = lerp(pawn.velocity.X, 0.0, 0.04);
			pawn.velocity.Y = lerp(pawn.velocity.Y, 0.0, 0.04);
			pawn.velocity.Z = lerp(pawn.velocity.Z, 0.0, 0.04);
			}
		if ( bCheatFlying && (Pawn.Acceleration == vect(0,0,0)) )
			Pawn.Velocity = vect(0,0,0);
		// Update rotation.

		if ( Role < ROLE_Authority ) // then save this move and replicate it
			ReplicateMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
		else
			ProcessMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
	}

	event BeginState(Name PreviousStateName)
	{
		Pawn.SetPhysics(PHYS_Flying);
		
	}
  exec function StartFire(optional byte FireModeNum)
  {
	UTPawn(Pawn).SetMeshVisibility(true);
	 `Log("Player");
	 GotoState('Commander');
	 Global.StartFire(FireModeNum);
    
  }
  function UpdateRotation(float DeltaTime){

  }
}
state Commander extends PlayerWalking
{
	  exec function StartFire(optional byte FireModeNum)
  {
	 `Log("Commander");

    Global.StartFire(FireModeNum);
  }
	function UpdateRotation(float DeltaTime){
		global.UpdateRotation(DeltaTime);
  }
}
function DeactivateSpawnProtectsion()
{
}
	function UpdateRotation(float DeltaTime){
		super.UpdateRotation(DeltaTime);
  }
exec function toggleshift(){
	FinalHUD(myHUD).shift = !FinalHUD(myHUD).shift;
}
exec function toggleEnter(){
	FinalHUD(myHUD).Enter = !FinalHUD(myHUD).Enter;
}
exec function toggleCtrl(){
	FinalHUD(myHUD).Ctrl = !FinalHUD(myHUD).Ctrl;
}





simulated function changeMode(){

}



DefaultProperties
{

  // Set the input class to the mouse interface player input
  InputClass=class'MyPlayerInput' 
	CameraClass = class'IsometricCamera'


}
